package com.yugu.park.system.service.impl;

import org.springframework.stereotype.Service;

import java.util.List;
import javax.annotation.Resource;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.transaction.annotation.Transactional;
import com.github.pagehelper.PageInfo;
import com.yugu.util.SearchPage;
import com.yugu.util.StringUtils;
import com.yugu.park.system.mapper.SysOperLogMapper;
import com.yugu.park.system.entity.SysOperLogEntity;
import com.yugu.park.system.service.SysOperLogService;
import cn.hutool.core.lang.UUID;
import com.github.pagehelper.PageHelper;

@Service
@Transactional
public class SysOperLogServiceImpl extends ServiceImpl<SysOperLogMapper, SysOperLogEntity> implements SysOperLogService {
    @Resource
	private SysOperLogMapper mapper;
	@Override
	public PageInfo<SysOperLogEntity> page(SearchPage<SysOperLogEntity> search) {
		PageHelper.startPage(search.getPageNum(),search.getPageSize());
        List<SysOperLogEntity> list = mapper.page(search.getSearch());
        return PageInfo.of(list);
	}
	@Override
	public void addOrUpdate(SysOperLogEntity t) {
		SysOperLogEntity old = mapper.selectById(t.getId());
		if(old!=null) {
			Integer businessType = t.getBusinessType();
			if(businessType!=null) {
				old.setBusinessType(businessType);
			}
			String errMsg = t.getErrMsg();
			if(StringUtils.isNotEmpty(errMsg)) {
				old.setErrMsg(errMsg);
			}
			String method = t.getMethod();
			if(StringUtils.isNotEmpty(method)) {
				old.setMethod(method);
			}
			String operIp = t.getOperIp();
			if(StringUtils.isNotEmpty(operIp)) {
				old.setOperIp(operIp);
			}
			String operLocation = t.getOperLocation();
			if(StringUtils.isNotEmpty(operLocation)) {
				old.setOperLocation(operLocation);
			}
			String operName = t.getOperName();
			if(StringUtils.isNotEmpty(operName)) {
				old.setOperName(operName);
			}
			String operParam = t.getOperParam();
			if(StringUtils.isNotEmpty(operParam)) {
				old.setOperParam(operParam);
			}
			String operResult = t.getOperResult();
			if(StringUtils.isNotEmpty(operResult)) {
				old.setOperResult(operResult);
			}
			Integer operType = t.getOperType();
			if(operType!=null) {
				old.setOperType(operType);
			}
			String operUrl = t.getOperUrl();
			if(StringUtils.isNotEmpty(operUrl)) {
				old.setOperUrl(operUrl);
			}
			String requestMethod = t.getRequestMethod();
			if(StringUtils.isNotEmpty(requestMethod)) {
				old.setRequestMethod(requestMethod);
			}
			Integer status = t.getStatus();
			if(status!=null) {
				old.setStatus(status);
			}
			String title = t.getTitle();
			if(StringUtils.isNotEmpty(title)) {
				old.setTitle(title);
			}
			mapper.updateById(old);
		}else{
			t.setId(UUID.randomUUID().toString().replaceAll("-", ""));
			mapper.insert(t);
		}
	}

}
